//function $(id){return document.getElementById(id);}
function createObj() {
	var o = null;
	if (typeof(XMLHttpRequest) != "undefined") return new XMLHttpRequest();
	if (window.ActiveXObject) {
		var MSXML = ["MSXML2.XMLHttp.6.0", "MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp", "Microsoft.XMLHTTP"];
		for (var i = 0; i < MSXML.length; i++) {
			try {
				o = new ActiveXObject(MSXML[i]);
				return o;
			}
			catch(e) {}
		}
	}
	return null;
}

function SendData(v, name, spanname) {
	var o = createObj();
	if (name == "confirmpassword") {
		if ($('#inputpassword')[0].value == $('#confirmpassword')[0].value) $('#' + spanname)[0].innerHTML = "{lang valid}";
		else $('#' + spanname)[0].innerHTML = "{lang invalid}: {lang not_match}";
		return;
	}
	var url = "ajax.php?" + name + "=" + v;
	o.open("get", url, true);
	o.onreadystatechange = function() {
		if (o.readyState == 4) {
			if (o.status == 200) $('#' + spanname)[0].innerHTML = o.responseText;
			else alert("{lang error_occur}");
		}
	}
	o.send(null);
}
function EnableObject(v) {
	if ($('#' + v)[0].getAttribute('disabled')) {
		$('#' + v)[0].removeAttribute('disabled');
	}
}

function show(element, type, n) {
	var allChild = $('#' + element)[0].getElementsByTagName(type);
	for (i = 0; i < allChild.length; i++) {
		if (i == n) allChild[i].style.display = "block";
		else allChild[i].style.display = "none";
	}
}

function makenewoptions() {
	answers = $('#choice')[0].value.split("\n");
	k = 1;
	for (i = $('#answer')[0].options.length - 1; i >= 0; i--) $('#answer')[0].options.remove(i);
	for (i = 0; i < answers.length; i++) {
		var item = new Option(answers[i], k);
		$('#answer')[0].options.add(item);
		k *= 2;
	}
}
function mmakenewoptions() {
	answers = $('#mchoice')[0].value.split("\n");
	k = 1;
	for (i = $('#manswer')[0].options.length - 1; i >= 0; i--) $('#manswer')[0].options.remove(i);
	for (i = 0; i < answers.length; i++) {
		var item = new Option(answers[i], k);
		$('#manswer')[0].options.add(item);
		k *= 2;
	}
}
$(document).ready(function() {
	$("input[name='score']").change(function() {
		var res = $(this);
		$.ajax({
			url: 'ajax.php',
			type: 'get',
			data: {
				score: res.val(),
				ajax: true
			},
			success: function(html) {
				res.next().html(html);
			},
			beforeSend: function() {
				res.next().html("Loading...");
			}
		});
	});
	$("#inputusername").change(function() {
		var res = $(this);
		$.ajax({
			url: 'ajax.php',
			type: 'get',
			data: {
				username: res.val(),
				ajax: true
			},
			success: function(html) {
				res.next().html(html);
			},
			beforeSend: function() {
				res.next().html("Loading...");
			}
		});
	});
	$("#inputpassword").change(function() {
		var res = $(this);
		$.ajax({
			url: 'ajax.php',
			type: 'get',
			data: {
				password: res.val(),
				ajax: true
			},
			success: function(html) {
				res.next().html(html);
			},
			beforeSend: function() {
				res.next().html("Loading...");
			}
		});
		if ($('#inputpassword').val() == $('#confirmpassword').val()) {
			$(this).next().html("可以使用");
		}
		else {
			$(this).next().html("两次输入的密码不匹配");
		}
	});
	$("#confirmpassword").change(function() {
		if ($('#inputpassword').val() == $('#confirmpassword').val()) {
			$(this).next().html("可以使用");
		}
		else {
			$(this).next().html("两次输入的密码不匹配");
		}
	});
	$("#studentid").change(function() {
		var res = $(this);
		$.ajax({
			url: 'ajax.php',
			type: 'get',
			data: {
				studentid: res.val(),
				ajax: true
			},
			success: function(html) {
				res.next().html(html);
			},
			beforeSend: function() {
				res.next().html("Loading...");
			}
		});
	});
	$("#inputemail").change(function() {
		var res = $(this);
		$.ajax({
			url: 'ajax.php',
			type: 'get',
			data: {
				email: res.val(),
				ajax: true
			},
			success: function(html) {
				res.next().html(html);
			},
			beforeSend: function() {
				res.next().html("Loading...");
			}
		});
	});
	$("#inputmobile").change(function() {
		var res = $(this);
		$.ajax({
			url: 'ajax.php',
			type: 'get',
			data: {
				mobile: res.val(),
				ajax: true
			},
			success: function(html) {
				res.next().html(html);
			},
			beforeSend: function() {
				res.next().html("Loading...");
			}
		});
	});
	$("#inputrealname").change(function() {
		var res = $(this);
		$.ajax({
			url: 'ajax.php',
			type: 'get',
			data: {
				realname: res.val(),
				ajax: true
			},
			success: function(html) {
				res.next().html(html);
			},
			beforeSend: function() {
				res.next().html("Loading...");
			}
		});
	});
	
});